package com.renshuai.demo.mybatis.config;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import org.apache.ibatis.annotations.Select;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
//		BeanDefinition beanDefinition = beanFactory.getBeanDefinition("user");
//		beanDefinition.setBeanClassName("com.renshuai.demo.mybatis.entity.Order");
		System.out.println("postProcessBeanFactory");
		OrderMapper mapper = (OrderMapper) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {OrderMapper.class}, new MyInvocationhandler());
		
		beanFactory.registerSingleton("orderMapper", mapper);
	}

	public MyBeanFactoryPostProcessor() {
		super();
		System.out.println("MyBeanFactoryPostProcessor");
	}
	
}
